﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using BLL;

namespace Sales
{
    public partial class PrintAgain : Form
    {
        private static PrintAgain printagain = null;
        public PrintAgain()
        {
            InitializeComponent();
            DataBind(" top 20", "");

        }
        public static PrintAgain CreateInstance()
        {
            if (null == printagain)
            {
                printagain = new PrintAgain();
            }
            return printagain;
        }

        public void DataBind(string top, string strWhere)
        {
            string sql = "select  " + top + "  sj 销售时间,djzt 单据状态,xsdh 销售单号,khbh 客户编号,khmc 客户名称,slhj 数量合计,jehj 金额合计   from dbo.xskdh  " + strWhere + " order by djlsh desc";
            BasicBLL basicBLL = new BasicBLL();
            DataTable dt = basicBLL.GetData(sql);
            if (dt != null && dt.Rows.Count > 0)
            {
                //foreach (DataRow dr in dt.Rows)
                //{
                //    dr.BeginEdit();

                //    dr["销售时间"] = dr["销售时间"].ToString().Replace('*', ':');

                 
                //    dr.EndEdit();
                //}
            }
            this.dataGridView1.DataSource = dt;
        }


        private void ctxtKey_TextChanged(object sender, EventArgs e)
        {
            string pyjm = this.ctxtKey.Text.Trim();// textBox1.Text.Trim();

            // string strWhere = "khbh like '" + pyjm + "%'  or khgm like '" + pyjm + "%' or khmc like '" + pyjm + "%'";
            string strWhere = " where xsdh like '" + pyjm + "%' or khbh like '" + pyjm + "%' or khmc like '" + pyjm + "%'";

            DataBind("", strWhere);
        }

       

        private void dataGridView1_DoubleClick(object sender, EventArgs e)
        {
            int index = this.dataGridView1.CurrentRow.Index;
            string xsdh = this.dataGridView1.Rows[index].Cells[2].Value.ToString();
            if (xsdh != "")
            {
                string guid = Guid.NewGuid().ToString();//随机数 确保不重复调用方法
                string msg = xsdh + "$" + guid;
                frmMain main = frmMain.CreateInstance();
                MiddleModule.SendMessage(this, main, msg);
                printagain = null;
                this.Close();
            }
            else
            {
                Message.MsgBoxInfo("请选择商品记录！");
            }
        }

    }
}
